import 'package:flutter/material.dart';
import 'package:flutter_1800/models/user.dart';
import 'package:flutter_1800/pages/goods/OrderList.dart';
import 'package:flutter_1800/pages/goods/addressList.dart';
import 'package:flutter_1800/pages/user/mineInfo.dart';
import 'package:flutter_1800/pages/widgets/MyText.dart';
import 'package:flutter_1800/pages/widgets/avatar.dart';
import 'package:flutter_1800/tools/AppUtil.dart';
import 'package:flutter_1800/tools/storage.dart';

import '../user/loginView.dart';

class MineTabViewPage extends StatefulWidget {
  const MineTabViewPage({Key? key}) : super(key: key);

  @override
  _MineTabViewPageState createState() => _MineTabViewPageState();
}

class _MineTabViewPageState extends State<MineTabViewPage> {
  var list = [];
  User? user;
  List goodsList = [];

  ///see AutomaticKeepAliveClientMixin

  @override
  void initState() {
    getUser();
    queryData();
  }

  void queryData() {}

  void getUser() async {
    user = await StorageUtil.getUser();
    setState(() {});
  }

  void logout() {
    StorageUtil.clearUser();
    AppUtil.getTo(const LoginViewPage());
  }

  @override
  Widget build(BuildContext context) {
    if (user == null) {
      return const Scaffold();
    }
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        shadowColor: Colors.transparent,
        centerTitle: true,
        elevation: 0.0,
        toolbarHeight: 40,
        title: MyText(
          "我的",
          weight: FontWeight.bold,
        ),
      ),
      body: SingleChildScrollView(
          child: Container(
        color: const Color.fromRGBO(240, 240, 240, 1),
        child: Column(
          children: [
            Container(
                decoration: const BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(15),
                        topRight: Radius.circular(15))),
                padding: AppUtil.getCommonPadding(),
                margin: const EdgeInsets.fromLTRB(10, 50, 10, 0),
                child: Column(
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          width: 60,
                          height: 60,
                          child: ClipRRect(
                            borderRadius: BorderRadius.circular(60),
                            child: Avatar(user!.headimg),
                          ),
                        ),
                        const SizedBox(width: 20),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            const SizedBox(height: 20),
                            Text(
                              user?.nickname ?? "爱吃的小胖子",
                              maxLines: 4,
                              textAlign: TextAlign.center,
                              style: const TextStyle(
                                  fontSize: 16,
                                  color: Color.fromRGBO(0, 0, 0, 1)),
                            ),
                          ],
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            const SizedBox(height: 20),
                            Row(
                                children: [
                                  const SizedBox(width: 10),
                                  GestureDetector(
                                    onTap: () {
                                      logout();
                                    },
                                    child: Container(
                                      padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(5),
                                        color: const Color.fromRGBO(255, 255, 255, 1),
                                        border: Border.all(
                                            color: const Color.fromRGBO(0, 0, 0, 1),
                                            width: 1),
                                      ),
                                      child: const Text(
                                        "退出",
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Color.fromRGBO(0, 0, 0, 1)),
                                      ),
                                    ),
                                  ),
                                  const SizedBox(width: 10),
                                  GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        AppUtil.showConfirm(context,
                                            title: "确认注销账号?", onConfirm: () {});
                                      },
                                      child: Container(
                                        padding: const EdgeInsets.fromLTRB(10, 5, 10, 5),
                                        decoration: BoxDecoration(
                                          borderRadius: BorderRadius.circular(5),
                                          color: const Color.fromRGBO(255, 255, 255, 1),
                                          border: Border.all(
                                              color: const Color.fromRGBO(0, 0, 0, 1),
                                              width: 1),
                                        ),
                                        child: Row(
                                          crossAxisAlignment: CrossAxisAlignment.center,
                                          children: [
                                            MyText("注销账号"),
                                          ],
                                        ),
                                      ))
                                ]
                            )
                          ],
                        )
                      ],
                    ),
                    const SizedBox(height: 20),
                    Container(
                      padding: const EdgeInsets.all(20),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        gradient: const LinearGradient(
                            begin: Alignment.topLeft,
                            end: Alignment.bottomRight,
                            colors: [Color(0xff686363), Color(0xff433b38)]),
                      ),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              MyText(
                                "会员卡",
                                color: Color(0xfffbe960),
                              ),
                            ],
                          ),
                          const SizedBox(height: 5),
                          Container(
                            height: 1,
                            color: const Color(0xff666666),
                          ),
                          const SizedBox(height: 10),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              GestureDetector(
                                child: Row(
                                  children: [
                                    Image.asset(
                                      "images/mall/scoreduihuan.png",
                                      width: 15,
                                      height: 15,
                                    ),
                                    const SizedBox(width: 3),
                                    MyText(
                                      "积分兑换",
                                      color: const Color(0xffbfb290),
                                      fontSize: 12,
                                    )
                                  ],
                                ),
                              ),
                              GestureDetector(
                                child: Row(
                                  children: [
                                    Image.asset(
                                      "images/mall/scoreduihuan.png",
                                      width: 15,
                                      height: 15,
                                    ),
                                    const SizedBox(width: 3),
                                    MyText(
                                      "生日券",
                                      color: const Color(0xffbfb290),
                                      fontSize: 12,
                                    )
                                  ],
                                ),
                              ),
                              GestureDetector(
                                child: Row(
                                  children: [
                                    Image.asset(
                                      "images/mall/scoreduihuan.png",
                                      width: 15,
                                      height: 15,
                                    ),
                                    const SizedBox(width: 3),
                                    MyText(
                                      "会员卡规则",
                                      color: Color(0xffbfb290),
                                      fontSize: 12,
                                    )
                                  ],
                                ),
                              ),
                              GestureDetector(
                                child: Row(
                                  children: [
                                    Image.asset(
                                      "images/mall/scoreduihuan.png",
                                      width: 15,
                                      height: 15,
                                    ),
                                    const SizedBox(width: 3),
                                    MyText(
                                      "消费有礼",
                                      color: Color(0xffbfb290),
                                      fontSize: 12,
                                    )
                                  ],
                                ),
                              )
                            ],
                          )
                        ],
                      ),
                    )
                  ],
                )),
            Container(
              margin: const EdgeInsets.fromLTRB(10, 10, 10, 10),
              padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
              decoration: const BoxDecoration(
                  color: Color.fromRGBO(255, 255, 255, 1),
                  borderRadius: BorderRadius.all(Radius.circular(5))),
              child: Row(
                children: [
                  Expanded(
                      flex: 1,
                      child: GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            AppUtil.getTo(OrderList(0));
                          },
                          child: const Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Image(
                                  image: AssetImage("images/mall/unpay.png"),
                                  width: 30,
                                  height: 30,
                                  fit: BoxFit.cover),
                              SizedBox(height: 10),
                              Text(
                                "待付款",
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Color.fromRGBO(100, 100, 100, 1)),
                              )
                            ],
                          ))),
                  Expanded(
                      flex: 1,
                      child: GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            AppUtil.getTo(OrderList(1));
                          },
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              ClipRRect(
                                child: const Image(
                                    image:
                                        AssetImage("images/mall/unsend.png"),
                                    width: 30,
                                    height: 30,
                                    fit: BoxFit.cover),
                                borderRadius: BorderRadius.circular(50),
                              ),
                              const SizedBox(height: 10),
                              const Text(
                                "待发货",
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Color.fromRGBO(100, 100, 100, 1)),
                              )
                            ],
                          ))),
                  Expanded(
                      flex: 1,
                      child: GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            AppUtil.getTo(OrderList(2));
                          },
                          child: const Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Image(
                                  image:
                                      AssetImage("images/mall/unrecieve.png"),
                                  width: 30,
                                  height: 30,
                                  fit: BoxFit.cover),
                              SizedBox(height: 10),
                              Text(
                                "待收货",
                                style: TextStyle(
                                    fontSize: 14,
                                    color: Color.fromRGBO(100, 100, 100, 1)),
                              )
                            ],
                          ))),
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.fromLTRB(10, 10, 10, 10),
              padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
              decoration: const BoxDecoration(
                  color: Color.fromRGBO(255, 255, 255, 1),
                  borderRadius: BorderRadius.all(Radius.circular(5))),
              child: Column(
                children: [
                  Row(
                    children: [
                      Expanded(
                          flex: 1,
                          child: GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                AppUtil.getTo(const MineInfo());
                              },
                              child: const Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image(
                                      image:
                                          AssetImage("images/gerenxinxi.png"),
                                      width: 20,
                                      height: 20,
                                      fit: BoxFit.cover),
                                  SizedBox(height: 10),
                                  Text(
                                    "个人信息",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color:
                                            Color.fromRGBO(100, 100, 100, 1)),
                                  )
                                ],
                              ))),
                      Expanded(
                          flex: 1,
                          child: GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                AppUtil.getTo(AddressList(() {}));
                              },
                              child: const Column(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  Image(
                                      image: AssetImage("images/address.png"),
                                      width: 20,
                                      height: 20,
                                      fit: BoxFit.cover),
                                  SizedBox(height: 10),
                                  Text(
                                    "收货地址",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color:
                                            Color.fromRGBO(100, 100, 100, 1)),
                                  )
                                ],
                              ))),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      )),
    );
  }
}
